package com.zhongxia.controller;

import com.zhongxia.entity.Order;
import com.zhongxia.entity.OrderVO;
import com.zhongxia.mapper.OrderMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import javax.websocket.server.PathParam;
import java.util.Date;
import java.util.List;

/**
 * @Author: 废柴弟弟
 * @Date: 2020/3/3 20:43
 */
@RestController
@RequestMapping("order")
public class OrderController {
   @Autowired
    private OrderMapper orderMapper;
   @PostMapping("save")
    public void save(@RequestBody Order order)
   {
       order.setDate(new Date());
       orderMapper.save(order);
   }
   @GetMapping("findAllByUid/{index}/{limit}/{uid}")
    public OrderVO findAllByUid(@PathVariable("index") int index, @PathVariable("limit") int limit, @PathVariable("uid") int uid)
   {
       OrderVO orderVO=new OrderVO();
       orderVO.setMsg("");
       orderVO.setCount(orderMapper.count(uid));
       orderVO.setData(orderMapper.findAllByUid(index, limit, uid));
       return orderVO;
   }
   @GetMapping("count/{uid}")
   public int count(@PathVariable("uid") int uid)
   {
       return orderMapper.count(uid);
   }
    @GetMapping("findAll/{index}/{limit}")
    public OrderVO findAll(@PathVariable("index") int index, @PathVariable("limit") int limit)
    {
        OrderVO orderVO=new OrderVO();
        orderVO.setMsg("");
        orderVO.setCount(orderMapper.countByState());
        orderVO.setData(orderMapper.findAll(index, limit));
        return orderVO;
    }
    @PutMapping("update/{id}")
    public void update(@PathVariable("id") int id)
    {
        orderMapper.update(id);
    }
}
